package com.heo.coder.packet;

import com.heo.coder.packet.base.BasePacket;
import com.heo.util.ByteHelper;
import com.heo.util.DeviceCommand;

public class SetIpPortPacketRsp extends BasePacket{

	public SetIpPortPacketRsp() throws Exception {
		super("", 0, "", DeviceCommand.SET_IP_PORT_COMMAND_RSP, "");
	}
	
	/**
	 * 
	 * @param ip  
	 * @param port  
	 */
	public void setMsgContent(String ip, int port) {
		String asciiStr = ByteHelper.stringToAsciiHexString("click1.cn");
		StringBuilder sBuilder = new StringBuilder(asciiStr);
		int length = 64;
		if (asciiStr.length() < length) {
			int c = length - asciiStr.length();
			for (int i = 0; i < c; i++) {
				sBuilder.append("0");
			}
		}
		
		String lengthStr = ByteHelper.intToHexString(41, 2);
		setLengthStr(lengthStr);
		setBody("11" + ByteHelper.intToHexString(port, 4) + sBuilder.toString());
		checkData();
	}
	
	@Override
	public String toString() {
		return "SocketPacket: [" + control + "] [" + START_MARKER_LENGTH_CODE + getLengthStr() + getCheck() +  getControl() + getBody()  + "]";
	}

	@Override
	public String getPacketBody() {
		return super.body;
	}
}
